﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Nok_Air
{
    public class Validator
    {
        private static bool changed = false;
        private static void validateWithRegExp(TextBox box, string regexpPattern)
        {
            if (changed)
            {
                changed = false;
                return;
            }
            int i = box.SelectionStart;
            string current = box.Text;
            string name = current.ToUpper();
            System.Text.RegularExpressions.Regex pattern = new System.Text.RegularExpressions.Regex(regexpPattern);
            if (pattern.IsMatch(name))
            {
                name = name.Remove(--i, 1);
            }
            box.Text = name;
            box.SelectionStart = i;
            changed = true;

        }
        public static void validateName(TextBox box)
        {
            validateWithRegExp(box, "[^A-Z]");
        }

        public static void validateNumber(TextBox box)
        {
            validateWithRegExp(box, "[^0-9]");
        }
    }
}
